# -*- coding: utf-8 -*-
"""
# @Time    : 2021/1/11 下午5:04
# @Author  : tgy
"""
import subprocess


def test01():
    ...
    # subprocess.Popen('ls /',stdout=)
    result = subprocess.getoutput('ls /')
    # print(result)
    status, result = subprocess.getstatusoutput('cat /Users/apple/supersped.sh')
    if status == 0:
        print(result)
    else:
        print('读取失败:%s' % result)


def test02():
    ...
    run = subprocess.run(['ls', '-la', '/'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True)
    print(run.stdout.decode('utf-8'))



def test03():
    ...
    popen = subprocess.Popen('ls -al /', stdout=subprocess.PIPE, shell=True)
    print(popen.stdout.read().decode('utf-8'))


def test04():
    ...
    popen = subprocess.Popen(['python3'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
    popen.stdin.write(b'print(1)\n')
    popen.stdin.write(b'print(2)')
    out,err = popen.communicate()
    print(f'out:{out},err:{err}')


def test05():
    ...
    popen = subprocess.Popen(['cat'], stdout=subprocess.PIPE, stdin=subprocess.PIPE)
    popen.stdin.write('/Users/apple/superspeed.sh\n'.encode('utf-8'))
    print(popen.communicate())
    # print(popen.stdout.read())
    # wc_popen = subprocess.Popen('wc', stdin=popen.stdout, stdout=subprocess.PIPE)
    # print(wc_popen.stdout.read().decode('utf-8'))


if __name__ == '__main__':
    ...
    test05()